package com.tang.service;
import com.tang.Dao.BookDao;
import com.tang.pojo.Book;
import java.util.List;
public class BookServiceImpl implements BookServicve{
    @Override
    public Book queryABook(int id) {
        BookDao bd=new BookDao();
        return bd.queryABook(id);
    }
    @Override
    public List<Book> queryBooks() {
        BookDao bd=new BookDao();
        return bd.queryBooks();
    }
    @Override
    public void addBook(Book book) {
        BookDao bd=new BookDao();
        bd.insert(book);
        System.out.println("新增图书"+book.getName()+"成功");
    }
    @Override
    public void deleteBook(int id) {
        BookDao bd=new BookDao();
        if(bd.queryABook(id)==null){
            System.out.println("删除图书失败,该图书不存在");
        }else {
            bd.delete(id);
            System.out.println("删除图书成功");
        }
    }
    @Override
    public void updateBook(Book book,int id) {
        BookDao bd=new BookDao();
        if(bd.queryABook(id)==null) {
            System.out.println("修改图书信息失败,该图书不存在");
        }else {
            bd.update(book, id);
            System.out.println("修改图书信息成功");
        }
    }
}
